import axios from '@/libs/http'
import qs from 'qs'

/**
 * 用户登录
 */
export const login = loginData => {
  return axios({
    method: 'post',
    url: '/auth/login',
    data: loginData
  })
}

/**
 * 获取用户信息
 */
export const getUserInfo = userId => {
  return axios({
    method: 'get',
    url: '/auth/user/info/'+userId
  })
}

/**
 * 退出登录
 */
export const logout = ()=> {
  return axios({
    method: 'get',
    url: '/auth/logout/'
  })
}

/**
 * 分页获取用户数据
 */
export const getUserList = ({pageSize,pageNum,username,phone,email}) =>{
  return axios({
    method: 'post',
    url: '/auth/user/list',
    data:{
      pageSize,
      pageNum,
      username,
      phone,
      email
    }
  })
}

/**
 * 获取用户菜单树
 */
export const getMenuTree = ({userId, sysCode}) =>{
  return axios({
    method: 'post',
    url: '/auth/menus',
    data:{
      userId,
      sysCode
    }
  })
}

/**
 * 检查账号是否存在
 */
export const checkAccount = account =>{
  return axios({
    method: 'get',
    url: '/auth/checkAccount/'+account
  })
}

/**
 * 检查手机号是否存在
 */
export const checkPhone = data =>{
  return axios({
    method: 'post',
    url: '/auth/checkPhone',
    data: data
  })
}

/**
 * 检查邮箱是否存在
 */
export const checkEmail = data =>{
  return axios({
    method: 'post',
    url: '/auth/checkEmail',
    data: data
  })
}

/**
 * 添加用户
 */
export const addUser = data => {
  return axios({
    method: 'post',
    url: '/auth/user?action=add',
    data:data
  })
}

/**
 * 获取用户角色
 */
export const getRole = userId => {
  return axios({
    method: 'get',
    url: '/auth/role/'+userId
  })
}

/**
 * 获取所有用户角色
 */
export const getAllRole = () => {
  return axios({
    method: 'get',
    url: '/auth/roles'
  })
}

/**
 * 修改用户信息
 */
export const editUser = data => {
  return axios({
    method: 'post',
    url: '/auth/user?action=upd',
    data:data
  })
}

/**
 * 删除用户
 */
export const deleteUser = userId => {
  let data = {'userId': userId}
  return axios({
    method: 'post',
    url: '/auth/user?action=del',
    data: qs.stringify(data)
  })
}
